package Pearl.dao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import Pearl.beans.Users;
import Pearl.db.DbConnect;

public class AuthentificationDaoImp implements AuthentificationDao{

	private static final Logger log = Logger.getLogger(AuthentificationDaoImp.class);
	
	public Users UsersauthentifLogin(String email)throws SQLException{
		
		try{
			CallableStatement callst = null;
			ResultSet rs = null;
			Users myUsers =new Users();
			
			callst = DbConnect.getInstance().prepareCall("Call rechUsers(?)");
			log.debug("chargement : OK ");
			
			callst.setString(1, email);
			rs=callst.executeQuery();
			while(rs.next()){
				myUsers.setId_users(rs.getInt("id_Users"));
				myUsers.setType(rs.getString("type"));
				myUsers.setName(rs.getString("name"));
				myUsers.setfName(rs.getString("fName"));
				myUsers.setNickname(rs.getString("nickname"));
				myUsers.setPhone(rs.getString("phone"));
				myUsers.setId_address(rs.getInt("id_address"));
				myUsers.setId_address_liv(rs.getInt("id_address_liv"));
				myUsers.setIp(rs.getString("ip"));
				myUsers.setEmail(rs.getNString("email"));
				myUsers.setPwd(rs.getString("pwd"));
				myUsers.setFlag(rs.getInt("flag"));
				myUsers.setRegtime(rs.getDate("regtime"));
				myUsers.setNewsletter(rs.getString("newsletter"));
				myUsers.setId_role(rs.getInt("id_role"));
				
			}
			log.debug("Execution : OK");
			
			return myUsers;
			
		}
		catch(SQLException sqlex){
			log.error("Execution : Echec");
			return null;
		}
	}

	@Override
	public Users authentificationLogin(String logIn) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
}
